Version 3.0
User's Guide

Accessing Global Variables

Previous | Next
Contents

Variables, as we have discussed, are available in three types: Global, Local, and User. Local and User variables last only as long as a page is being served or a user is visiting your site. Because they are relatively temporary, these variables can not be directly edited. Global variables, by contrast, are permanent, and can be set directly using the NetCloak CGI or the Web admin interface.

To set global variables with the CGI, select the "Variables..." command from the "Configuration" menu, and click the "Variables" tab.


Figure 18: The Variables tab of the NetCloak Lists window.

Creating, modifying, and deleting Global variables is easy. To create a variable, simply enter it's name and value, and click the "Save Changes" button. To modify an existing variable, click on it in the "Variables" list, edit the value, and click "Save Changes". To delete a variable, simply select it in the list and click "Remove Variable".

To edit global variables using the Web admin interface, go to the NetCloak Web admin URL in your Web browser, then click the "Global Variables" link.


Figure 19: The Global Variables page of the NetCloak Web admin interface.

To delete a global variable, click the radio button next to the variable's name, then click the "Remove" button.

To create a new global variable, click the "New..." button. To edit an existing global variable, click the radio button next to the variable's name, then click the "Edit..." button. Either way, you are shown the "Edit Global Variable" page.


Figure 20: The Edit Global Variable page of the NetCloak Web admin interface.

Type changes to the variables name and/or value into the text fields, then click the "Save Changes" button for the change to take effect.

Global variables changed in the CGI or the Web admin pages will be immediately reflected when used in commands on your site. This is an excellent way to simplify site maintenance. For example, assume each of your pages used a macro for the page header. You could put something like this in the macro:

    <HIDE><SHOW_GLOBAL MaintMode "On">    <REDIRECT "http://mysite.com/MaintMode.html">    <SHOW>

"MaintMode.html" could be a page that tells visitors that the site is currently being revised and that they should check back later. Now, any time you need to make major revisions to the site, you can just edit the Global variable so that it's value is "On". When you are done making changes, change the value to "Off" and the site will be accessible again.

Using AppleScript to Access Global Variables

NetCloak includes the ability to set and get global variable values using AppleScript or any application capable of sending AppleEvents.

The "Get Global" Event

To get the value of a global variable in the NetCloak CGI using AppleScript, use the following script syntax, replacing "varName" with the name of the global variable you want to get:

    tell application "NetCloak.acgi"        set varValue to get global "varName"    end tell

This script sets the value of the script variable "varValue" to the value of the global variable. An example script using this syntax, named "Get Global via NetCloak.acgi", is in the "Sample Scripts" folder.

Because the NetCloak Plug-In cannot publish its AppleScript dictionary when it is running inside the Web server, you must use the raw AppleEvent codes in a script designed to communicate with the NetCloak Plug-In. For example, the equivalent script to talk to the NetCloak Plug-In would look like this:

    tell application "WebSTAR 2.1.1"        set varValue to «event NClkGetG» "varName"    end tell

Note two differences: you must "tell" the Web server, not the plug-in, what to do; and you must use the raw event code "«event NClkGetG»". To enter the special '«' character, type "option-\" (hold down the option key while typing the backslash character), and type "option-shift-\" to enter the '»' character. This is necessary because the Plug-In actually becomes part of the Web server when it is running, but it cannot modify the Web server's AppleScript dictionary. See the "Get Global via WebSTAR" script in the "Sample Scripts" folder.

To send the "Get Global" event to NetCloak using some other application that requires you to enter the AppleEvent codes for the "event class", "event ID" and "event parameters", you will need to know the following information. Consult the application's documentation for specific instructions on how to use this information.

Event Class: 'NClk'
Event ID:    'GetG'

Parameters:
The direct parameter '----' of the event is type 'char' and contains the name 
of the global variable. 

Reply:
The direct parameter '----' of the reply event is type 'char' and contains the 
variable's value.

The "Set Global" Event

To set the value of a global variable in the NetCloak CGI using AppleScript, use the following script syntax, replacing "varName" and "varValue" with the name of the global variable and the value you want to set it to:

    tell application "NetCloak.acgi"        set global "varName" to "varValue"    end tell

An example script using this syntax, named "Set Global via NetCloak.acgi", is in the "Sample Scripts" folder.

Because the NetCloak Plug-In cannot publish its AppleScript dictionary when it is running inside the Web server, you must use the raw AppleEvent codes in a script designed to communicate with the NetCloak Plug-In via the Web server. For example, the equivalent script to talk to the NetCloak Plug-In would look like this:

    tell application "WebSTAR 2.1.1"        «event NClkSetG» "varName" given «class valu»:"varValue"    end tell

Note two differences: you must "tell" the Web server, not the plug-in, what to do; and you must use the raw event codes. See the "Set Global via WebSTAR" script in the "Sample Scripts" folder.

To send the "Set Global" event to NetCloak using some other application that requires you to enter the AppleEvent codes for the "event suite", "event class" and "event parameters", you will need to know the following information. Consult the application's documentation for specific instructions on how to use this information.

Event Class: 'NClk'
Event ID:    'SetG'

Parameters:
The direct parameter '----' of the event is type 'char' and contains the name
of the global variable. 

A 'valu' parameter is also required; it is type 'char' and contains the new 
value for the global variable.

Reply:
There is no reply to the "Set Global" event.

Copyright © 1996-1999 Maxum Development Corporation

http://www.maxum.com/
Previous | Next
Contents